<%@ page language="java" import="java.util.*,com.xq.shop.po.Role" pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@page import="com.xq.shop.service.admin.IMenuService"%>
<%@page import="com.xq.shop.util.AdminServiceFactory"%>
<%@page import="com.xq.shop.po.*"%>
<%@page import="com.xq.shop.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<jsp:include page="/jsp/admin/common.jsp" />
<jsp:include page="/jsp/formHead.jsp" />
<script type="text/javascript">
$().ready(function(){

	var selected = [${selected}];

	$.each(selected, function(key, val){
		$("input[name='menuId'][value='" + val + "']").prop("checked", true);
	});

	$("a.checkAll").click(function(){
		$this = $(this);
		if($this.attr("checked")){
			$this.attr("checked", false);
			$this.closest("tr.authorities").find("input[name='menuId']").prop("checked", false);
		} else {
			$this.attr("checked", true);
			$this.closest("tr.authorities").find("input[name='menuId']").prop("checked", true);
		}
	})

	$("#backButton").click(function(){
		location.href = basePath + "jsp/admin/setting/role_list.jsp";
	});

	//判断是否是编辑状态
	var in_edit = ${!empty role.id};
	
	if(in_edit){
		$("div.path").append("<span>角色修改</span>");
	} else {
		$("div.path").append("<span>角色创建</span>");
	}
});
</script>
</head>
<body>
	<div class="path">
		<a href="">首页</a> &raquo;
	</div>
	<form id="form_add" method="post" action="<%=basePath %>admin/role_save.do">
		<table class="input tabContent">
			<tr>
				<th>
					<input type="hidden" name="id" value="${role.id }"/>
					<span class="requiredField">*</span>名称:
				</th>
				<td>
					<input type="text" name="name" class="text" maxlength="200" value="${role.name }"/>
				</td>
			</tr>
			<tr>
				<th>
					描述:
				</th>
				<td>
					<input type="text" name="remark" class="text" maxlength="200" value="${role.remark }"/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					&nbsp;
				</td>
			</tr>
			<c:forEach var="map" items="${linkedHashMap}">
			<tr class="authorities">
				<th>
					<input type="checkbox" name="menu_1st" value="${map.key.id }" style="display: none;"/>
					<a href="javascript:;" title="全选此组权限" class="checkAll">${map.key.name }管理</a>
				</th>
				<td>
					<c:forEach var="menu" items="${map.value}">
					<span class="fieldSet">
						<label>
							<input name="menuId" type="checkbox" value="${menu.id }" />${menu.name}
						</label>
					</span>
					</c:forEach>
				</td>
			</tr>
			</c:forEach>
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<span class="tips" style="display: none;">系统内置角色不允许修改</span>
				</td>
			</tr>
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<input type="submit" class="button" value="确定" />
					<input type="button" id="backButton" class="button" value="返回" onclick="turnToList()"/>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>